AivenのCLI「Aiven Client」を使ってみた
はじめに
アライアンス統括部の佐々木です。AivenにはAiven ClientというCLIが用意されています。
今日はコレを試してみます。
やってみた
インストール
ローカル環境はMacBook Proで、Python3環境は構築済みです。pipを使ってaiven-clientをインストールします。
% sudo python3 -m pip install aiven-client
インストールされたことを確認します。
% which avn /usr/local/bin/avn
ログイン
コマンドラインからAivenにログインします。
% avn user login XXXX@XXXX.com XXXX@XXXX.com's Aiven password: INFO Aiven credentials written to: /Users/smokeynonkey/.config/aiven/aiven-credentials.json INFO Default project set as 'smokeymonkey-aedd' (change with 'avn project switch <project>')
プロジェクトの操作
最初に、Aivenが対応しているクライドとリージョンを確認します。
% avn cloud list CLOUD_DESCRIPTION CLOUD_NAME GEO_LATITUDE GEO_LONGITUDE GEO_REGION ============================================================== ============================== ============ ============= ============== Africa, South Africa - Amazon Web Services: Cape Town aws-af-south-1 -33.92 18.42 africa Africa, South Africa - Azure: South Africa North azure-south-africa-north -26.198 28.03 africa Asia, Bahrain - Amazon Web Services: Bahrain aws-me-south-1 26.07 50.55 south asia Asia, Hong Kong - Amazon Web Services: Hong Kong aws-ap-east-1 22.5 114.0 east asia Asia, Hong Kong - Azure: East Asia azure-eastasia 22.5 114.0 southeast asia Asia, Hong Kong - Google Cloud: Hong Kong google-asia-east2 22.5 114.0 east asia Asia, India - Amazon Web Services: Mumbai aws-ap-south-1 19.13 72.89 south asia Asia, India - Azure: Central India azure-india-central 19.08 72.88 south asia Asia, India - Azure: South India azure-india-south 13.08 80.27 south asia Asia, India - Azure: West India azure-india-west 19.13 72.89 south asia Asia, India - DigitalOcean: Bangalore do-blr 12.96 77.59 south asia Asia, India - Google Cloud: Delhi google-asia-south2 28.68 77.07 south asia Asia, India - Google Cloud: Mumbai google-asia-south1 19.08 72.88 south asia Asia, Indonesia - Google Cloud: Jakarta google-asia-southeast2 6.21 106.85 southeast asia Asia, Japan - Amazon Web Services: Tokyo aws-ap-northeast-1 35.68 139.68 east asia Asia, Japan - Azure: Japan East azure-japaneast 35.68 139.68 east asia Asia, Japan - Azure: Japan West azure-japanwest 35.68 136.68 east asia Asia, Japan - Google Cloud: Osaka google-asia-northeast2 34.694 135.502 east asia Asia, Japan - Google Cloud: Tokyo google-asia-northeast1 35.68 139.68 east asia Asia, Korea - Amazon Web Services: Seoul aws-ap-northeast-2 37.57 126.97 east asia Asia, Korea - Azure: Korea Central azure-korea-central 37.57 126.97 east asia Asia, Korea - Azure: Korea South azure-korea-south 35.18 129.08 east asia Asia, Korea - Google Cloud: Seoul google-asia-northeast3 37.57 126.97 east asia Asia, Singapore - Amazon Web Services: Singapore aws-ap-southeast-1 1.3 103.8 southeast asia Asia, Singapore - Azure: Southeast Asia azure-southeastasia 1.3 103.8 southeast asia Asia, Singapore - DigitalOcean: Singapore do-sgp 1.3 103.8 southeast asia Asia, Singapore - Google Cloud: Singapore google-asia-southeast1 1.3 103.8 southeast asia Asia, Singapore - UpCloud: Singapore upcloud-sg-sin 1.3 103.8 southeast asia Asia, Taiwan - Google Cloud: Taiwan google-asia-east1 23.98 120.53 east asia Australia, Canberra - Azure: Australia Central azure-australia-central -35.3 149.12 australia Australia, New South Wales - Amazon Web Services: Sydney aws-ap-southeast-2 -33.85 151.2 australia Australia, New South Wales - Azure: Australia East azure-australiaeast -33.85 151.2 australia Australia, New South Wales - Google Cloud: Sydney google-australia-southeast1 -33.85 151.2 australia Australia, New South Wales - UpCloud: Sydney upcloud-au-syd -33.85 151.2 australia Australia, Victoria - Azure: Australia Southeast azure-australiasoutheast -37.7 145.02 australia Australia, Victoria - Google Cloud: Melbourne google-australia-southeast2 -37.815 144.946 australia Canada, Ontario - Azure: Canada Central azure-canadacentral 45.7 -79.4 north america Canada, Ontario - DigitalOcean: Toronto do-tor 45.7 -79.4 north america Canada, Ontario - Google Cloud: Toronto google-northamerica-northeast2 45.7 -79.4 north america Canada, Quebec - Amazon Web Services: Canada Central aws-ca-central-1 45.3 -73.34 north america Canada, Quebec - Azure: Canada East azure-canadaeast 50.7 -69.4 north america Canada, Quebec - Google Cloud: Montrial google-northamerica-northeast1 45.5 -73.57 north america Europe, Belgium - Google Cloud: Belgium google-europe-west1 50.45 3.82 europe Europe, England - Amazon Web Services: London aws-eu-west-2 51.5 0.12 europe Europe, England - Azure: UK South azure-uksouth 52.5 0.12 europe Europe, England - DigitalOcean: London do-lon 51.5 0.12 europe Europe, England - Google Cloud: London google-europe-west2 51.5 0.12 europe Europe, Finland - Google Cloud: Finland google-europe-north1 60.5693 27.1878 europe Europe, Finland - UpCloud: Helsinki upcloud-fi-hel 60.17 24.97 europe Europe, France - Amazon Web Services: Paris aws-eu-west-3 48.85 2.35 europe Europe, France - Azure: France Central azure-france-central 48.86 2.35 europe Europe, Germany - Amazon Web Services: Frankfurt aws-eu-central-1 50.12 8.68 europe Europe, Germany - Azure: Germany North azure-germany-north 53.0736 8.8064 europe Europe, Germany - Azure: Germany West Central azure-germany-westcentral 50.1166 8.6833 europe Europe, Germany - DigitalOcean: Frankfurt do-fra 50.12 8.68 europe Europe, Germany - Google Cloud: Frankfurt google-europe-west3 50.12 8.68 europe Europe, Germany - UpCloud: Frankfurt upcloud-de-fra 50.12 8.68 europe Europe, Ireland - Amazon Web Services: Ireland aws-eu-west-1 53.33 -6.25 europe Europe, Ireland - Azure: North Europe azure-northeurope 53.33 -6.25 europe Europe, Italy - Amazon Web Services: Milan aws-eu-south-1 45.46 9.19 europe Europe, Netherlands - Azure: West Europe azure-westeurope 52.37 4.9 europe Europe, Netherlands - DigitalOcean: Amsterdam do-ams 52.37 4.9 europe Europe, Netherlands - Google Cloud: Netherlands google-europe-west4 53.44 6.84 europe Europe, Netherlands - UpCloud: Amsterdam upcloud-nl-ams 52.37 4.9 europe Europe, Norway - Azure: Norway East azure-norway-east 59.91 10.98 europe Europe, Norway - Azure: Norway West azure-norway-west 58.97 5.73 europe Europe, Poland - Google Cloud: Warsaw google-europe-central2 52.237 21.018 europe Europe, Poland - UpCloud: Warsaw upcloud-pl-waw 52.24 21.02 europe Europe, Spain - UpCloud: Madrid upcloud-es-mad 40.42 -3.72 europe Europe, Sweden - Amazon Web Services: Stockholm aws-eu-north-1 59.3293 18.0686 europe Europe, Switzerland - Azure: Switzerland North azure-switzerland-north 47.37 8.54 europe Europe, Switzerland - Google Cloud: Zucrich google-europe-west6 47.378 8.539 europe Europe, Wales - Azure: UK West azure-ukwest 48.5 0.12 europe Middle East, United Arab Emirates - Azure: Middle East azure-uae-north 25.26 55.31 middle east South America, Brazil - Amazon Web Services: Sao Paulo aws-sa-east-1 -23.55 -46.63 south america South America, Brazil - Azure: Brazil South azure-brazilsouth -23.55 -46.63 south america South America, Brazil - Google Cloud: Sao Paulo google-southamerica-east1 -23.53 -46.625 south america United States, California - Amazon Web Services: N. California aws-us-west-1 37.78 -122.42 north america United States, California - Azure: West US azure-westus 37.78 -122.42 north america United States, California - DigitalOcean: San Francisco do-sfo 37.78 -122.42 north america United States, California - Google Cloud: Los Angeles google-us-west2 34.05 -118.24 north america United States, California - UpCloud: San Jose upcloud-us-sjo 37.3 -121.96 north america United States, Illinois - Azure: North Central US azure-northcentralus 41.83 -87.85 north america United States, Illinois - UpCloud: Chicago upcloud-us-chi 41.83 -87.85 north america United States, Iowa - Azure: Central US azure-centralus 41.25 -95.87 north america United States, Iowa - Google Cloud: Iowa google-us-central1 41.25 -95.87 north america United States, Nevada - Google Cloud: Las Vegas google-us-west4 36.11 -115.17 north america United States, New York - DigitalOcean: New York do-nyc 40.7 -70.0 north america United States, New York - UpCloud: New York upcloud-us-nyc 40.73 -73.94 north america United States, Ohio - Amazon Web Services: Ohio aws-us-east-2 40.24 -82.88 north america United States, Oregon - Amazon Web Services: Oregon aws-us-west-2 45.52 -122.67 north america United States, Oregon - Google Cloud: Oregon google-us-west1 45.52 -122.67 north america United States, South Carolina - Google Cloud: South Carolina google-us-east1 33.0 -80.03 north america United States, Texas - Azure: South Central US azure-southcentralus 33.0 -98.5 north america United States, Utah - Google Cloud: Salt Lake City google-us-west3 40.76 -111.88 north america United States, Virginia - Amazon Web Services: N. Virginia aws-us-east-1 38.7 -78.15 north america United States, Virginia - Azure: East US azure-eastus 38.7 -78.15 north america United States, Virginia - Azure: East US 2 azure-eastus2 38.7 -78.15 north america United States, Virginia - Google Cloud: Northern Virginia google-us-east4 38.7 -78.15 north america United States, Washington - Azure: West US 2 azure-westus2 45.52 -122.67 north america United States, Wyoming - Azure: West Central US azure-westcentralus 45.52 -110.67 north america
現在のプロジェクトを確認します。アカウント作成のタイミングで作られたプロジェクトが存在しています。
% avn project list PROJECT_NAME DEFAULT_CLOUD CREDIT_CARD ================= ================== =========== smokeymonkey-aedd aws-ap-northeast-1 N/A
プロジェクトの詳細を確認します。
% avn project details PROJECT_NAME DEFAULT_CLOUD BILLING_CURRENCY VAT_ID ================= ================== ================ ====== smokeymonkey-aedd aws-ap-northeast-1 USD credit_card = N/A billing_address = country_code =
プロジェクトを追加してみます。今回はAWSのus-east-1リージョンに作成しました。
% avn project create smokeynmonkey-prj --cloud aws-us-east-1 PROJECT_NAME DEFAULT_CLOUD BILLING_CURRENCY VAT_ID ================= ============= ================ ====== smokeynmonkey-prj aws-us-east-1 USD credit_card = N/A billing_address = country_code = INFO Project 'smokeynmonkey-prj' successfully created and set as default project
プロジェクト一覧を表示して、作成されたことを確認します。smokeynmonkey-prjが増えています。
% avn project list PROJECT_NAME DEFAULT_CLOUD CREDIT_CARD ================= ================== =========== smokeynmonkey-prj aws-us-east-1 N/A smokeymonkey-aedd aws-ap-northeast-1 N/A
新しく作成したプロジェクトにスイッチします。
% avn project switch smokeynmonkey-prj INFO Set project 'smokeynmonkey-prj' as the default project
作成したプロジェクトの詳細を確認します。aws-us-east-1になっています。
% avn project details PROJECT_NAME DEFAULT_CLOUD BILLING_CURRENCY VAT_ID ================= ============= ================ ====== smokeynmonkey-prj aws-us-east-1 USD credit_card = N/A billing_address = country_code =
最初のプロジェクトのスイッチ後、作成したプロジェクトを削除します。
% avn project switch smokeymonkey-aedd INFO Set project 'smokeymonkey-aedd' as the default project % avn project delete smokeynmonkey-prj % avn project list PROJECT_NAME DEFAULT_CLOUD CREDIT_CARD ================= ================== =========== smokeymonkey-aedd aws-ap-northeast-1 N/A
サービスの作成
最初に、作成可能なサービスを確認します。
% avn service plans Used cloud not defined, only showing service types! Cassandra - Distributed NoSQL data store Plans: Elasticsearch - Search & Analyze Data in Real Time Plans: Grafana - Metrics Dashboard Plans: InfluxDB - Distributed Time Series Database Plans: Kafka - High-Throughput Distributed Messaging System Plans: Kafka Connect - Kafka Connect service Plans: Kafka MirrorMaker - Kafka MirrorMaker service Plans: M3 Aggregator - Aggregates metrics and provides downsampling Plans: M3DB - Distributed time series database Plans: MySQL - Relational Database Management System Plans: OpenSearch - Search & Analyze Data in Real Time, derived from Elasticsearch v7.10.2 Plans: PostgreSQL - Object-Relational Database Management System Plans: Redis - In-Memory Data Structure Store Plans:
サービスを作成するときにタイプ名を指定するのですが、プランの名前はそのまま使えないので、指定可能なタイプ名を確認します。
% avn service types SERVICE_TYPE DESCRIPTION ================= =================================================================================== cassandra Cassandra - Distributed NoSQL data store elasticsearch Elasticsearch - Search & Analyze Data in Real Time grafana Grafana - Metrics Dashboard influxdb InfluxDB - Distributed Time Series Database kafka Kafka - High-Throughput Distributed Messaging System kafka_connect Kafka Connect - Kafka Connect service kafka_mirrormaker Kafka MirrorMaker - Kafka MirrorMaker service m3aggregator M3 Aggregator - Aggregates metrics and provides downsampling m3db M3DB - Distributed time series database mysql MySQL - Relational Database Management System opensearch OpenSearch - Search & Analyze Data in Real Time, derived from Elasticsearch v7.10.2 pg PostgreSQL - Object-Relational Database Management System redis Redis - In-Memory Data Structure Store
ではサービスを作成します。testdbは作成するサービスの名前です。タイプはMySQLを指定しています。
% avn service create testdb -t mysql --plan startup-4
サービスのリストを表示します。作成直後はSTATEがREBUILDINGになっています。
% avn service list SERVICE_NAME SERVICE_TYPE STATE CLOUD_NAME PLAN CREATE_TIME UPDATE_TIME NOTIFICATIONS ============ ============ ========== ================== ========= ==================== ==================== ============= testdb mysql REBUILDING aws-ap-northeast-1 startup-4 2021-12-02T06:47:55Z 2021-12-02T06:48:07Z
しばらく待つとSTATEがRUNNINGに変わります。
% avn service list SERVICE_NAME SERVICE_TYPE STATE CLOUD_NAME PLAN CREATE_TIME UPDATE_TIME NOTIFICATIONS ============ ============ ======= ================== ========= ==================== ==================== ============= testdb mysql RUNNING aws-ap-northeast-1 startup-4 2021-12-02T06:47:55Z 2021-12-02T06:53:56Z
aiven-clientにはサービスクライアントも実装されているのですが、現時点ではInfluxDBとPostgreSQLにしか対応していません。
% avn service cli testdb ERROR command failed: UserError: Unsupported service type mysql. Only InfluxDB and PostgreSQL are supported
ということでmysqlshを使って接続確認をします。
% mysqlsh --sql "mysql://XXXX@testdb-smokeymonkey-aedd.aivencloud.com:28813/defaultdb?ssl-mode=REQUIRED" MySQL Shell 8.0.22 Copyright (c) 2016, 2020, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type '\help' or '\?' for help; '\quit' to exit. WARNING: Using a password on the command line interface can be insecure. Creating a Classic session to 'XXXX@testdb-smokeymonkey-aedd.aivencloud.com:28813/defaultdb?ssl-mode=REQUIRED' Fetching schema names for autocompletion... Press ^C to stop. Fetching table and column names from `defaultdb` for auto-completion... Press ^C to stop. Your MySQL connection id is 32 Server version: 8.0.26 Source distribution Default schema set to `defaultdb`. MySQL testdb-smokeymonkey-aedd.aivencloud.com:28813 ssl defaultdb SQL > \q Bye!
サービスを停止します。
% avn service update testdb --power-off % avn service list SERVICE_NAME SERVICE_TYPE STATE CLOUD_NAME PLAN CREATE_TIME UPDATE_TIME NOTIFICATIONS ============ ============ ======== ================== ========= ==================== ==================== ============= testdb mysql POWEROFF aws-ap-northeast-1 startup-4 2021-12-02T07:14:57Z 2021-12-02T07:22:06Z
サービスを起動します。
% avn service update testdb --power-on % avn service list SERVICE_NAME SERVICE_TYPE STATE CLOUD_NAME PLAN CREATE_TIME UPDATE_TIME NOTIFICATIONS ============ ============ ========== ================== ========= ==================== ==================== ============= testdb mysql REBUILDING aws-ap-northeast-1 startup-4 2021-12-02T07:14:57Z 2021-12-02T07:23:28Z
サービスのログを確認します。
% avn service logs testdb 2021-12-02T07:19:49.613852 testdb-1 mysqld.service 2021-12-02T07:19:49.586839Z 0 [System] [MY-010116] [Server] /usr/bin/mysqld (mysqld 8.0.26) starting as process 264 2021-12-02T07:19:49.613168 testdb-1 mysqld.service 2021-12-02T07:19:49.586674Z 0 [Warning] [MY-011068] [Server] The syntax 'slave_parallel_type' is deprecated and will be removed in a future release. Please use replica_parallel_type instead. 2021-12-02T07:19:49.613168 testdb-1 mysqld.service 2021-12-02T07:19:49.586722Z 0 [Warning] [MY-011069] [Server] The syntax '--transaction-write-set-extraction' is deprecated and will be removed in a future release. ...
最後にサービスを削除します。
% avn service terminate testdb *********************************************************************** Please re-enter the service name(s) to confirm the service termination. This cannot be undone and all the data in the service will be lost! Re-entering service name(s) can be skipped with the --force option. *********************************************************************** Re-enter service name 'testdb' for immediate termination: testdb INFO testdb: terminated % avn service list
イベントの確認
以下コマンドでaivenのイベントログを確認できます。
% avn events TIME ACTOR EVENT_TYPE SERVICE_NAME EVENT_DESC ==================== ====================== ===================================== ============== =============================================================================================================================================================================== 2021-12-02T07:28:52Z smokeymonkey@gmail.com service_delete testdb Deleted service 2021-12-02T07:28:14Z Aiven Automation service_master_promotion testdb Promoted testdb-2 to be the new master in service testdb.
ログアウト
Aivenからログアウトします。ログアウト後にコマンドを投げてもエラーになります。
$ avn user logout % avn cloud list ERROR command failed: UserError: authentication is required to list clouds for a specific project
さいごに
正直GUIを操作するの面倒なので、コマンドラインで操作できるのは本当にありがたいです。ブログを書くときに画面キャプチャ取らなくて良いのも助かります(笑)